using System;
using THANHTUNGO.Portal.Components.UI;

namespace THANHTUNGO.Portal.Modules.STORE
{
    public enum STOREPages
    {
        Item,
        Detail
    }

    public partial class Main : PortalModuleControl
    {
        private void loadChildControl()
        {
            string m_baseDir = "~/Modules/STORE/";
            string pageQuery = "Page" + this.ModuleID;
            string pageName = Request.QueryString[pageQuery];

            STOREPages page;
            if (pageName == null)
            {
                page = STOREPages.Item;
            }
            else
            {
                page = (STOREPages)Enum.Parse(typeof(STOREPages), Request.QueryString[pageQuery], true);
            }

            string src = string.Format("{0}Pages/{1}.ascx", m_baseDir, page);
            if (src.IndexOf("/Mod_") >= 0)
                src = src.Replace("/Mod_", "/Mod/");
            if (src.IndexOf("/Admin_") >= 0)
                src = src.Replace("/Admin_", "/Admin/");
            if (src.IndexOf("/Help_") >= 0)
                src = src.Replace("/Help_", "/Help/");

            YAFPage ctl = (YAFPage)this.LoadControl(src);
            ctl.ParentControl = this;            
            this.Controls.Add(ctl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.loadChildControl();
        }
    }
}